package com.atguigu.day19.lambda;

import org.junit.Test;

import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;

public class LambdaTest {

    @Test
    public void test04(){
        HashMap<String, String> map = new HashMap<>();
        map.put("射手", "后羿");
        map.put( "打野", "典韦");
        map.put("辅助", "孙膑");
        map.put("打野", "典韦");

        /*map.replaceAll(new BiFunction<String, String, String>() {
            @Override
            public String apply(String s, String s2) {
                return "";
            }
        });*/
        map.replaceAll((s1,s2)->
             (s1.startsWith("打") & s2.length()>=2) ? "鲁班" : s2);
        System.out.println("map = " + map);
    }


    @Test
    public void test03(){
     //todo 功能型
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list,"李白","杜甫","辛弃疾","李商隐","欧阳修");
/*
        list.replaceAll(new UnaryOperator<String>() {
            @Override
            public String apply(String s) {
                //把姓李的 变为安琪拉
             *//*   if(s.startsWith("李")){
                    return "安琪拉";
                }
                return s;*//*
                return s.startsWith("李")?"安琪拉":s;
            }
        });*/
        //把姓李的 变为安琪拉
      //  list.replaceAll(s->s.startsWith("李")?"安琪拉plus":s);
        //将长度>=3的变为张良
        list.replaceAll(s-> s.length()>=3?"张良":s);


        list.forEach(e-> System.out.println("e = "+ e));
    }



    @Test
    public void test02(){
        //todo 判断型接口展示
        HashSet<Integer> set = new HashSet<>();

        Collections.addAll(set,10,11,12,13,14,15,16,17,18,19,20);

        set.removeIf(e->e%2==0);

        set.forEach(i-> System.out.println("i = "+i));
    }


    @Test
    public void test01(){
        //todo 判断型接口展示
        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list,10,11,12,13,14,15,16,17,18,19,20);

      /*  list.removeIf(new Predicate<Integer>() {
            @Override
            public boolean test(Integer e) {
               // System.out.println("integer = " + integer);
             *//*   if(e%2==0) {
                    return true;
                }
                return false;*//*

                //return e%2==0?true:false;
                return e%2==0;
            }
        });*/

        //保留偶数
        list.removeIf(e->e%2!=0);



        list.forEach(s-> System.out.println("s = "+ s));



    }
}
